package Exercise1;

import java.io.*;
import java.util.Properties;

public class IOTest3 {
    public static void main(String args[]) throws IOException, ClassNotFoundException {
        Properties properties = new Properties();
        properties.load(new FileReader("com.guigu.IO\\dog.properties"));
        String name = properties.getProperty("name");
        int age = Integer.parseInt(properties.getProperty("age"));
        String color = properties.getProperty("color");
        Dog dog = new Dog(name, age, color);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("com.guigu.IO\\dog.dat"));
        oos.writeObject(dog);
        oos.close();
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("com.guigu.IO\\dog.dat"));
        Dog o = (Dog)ois.readObject();
        System.out.println(o);
    }
}

class Dog implements Serializable
{
    public static final long serialVersionUID = 1246531165456L;
    private String name;
    private int age;
    private String color;

    public Dog() {
    }

    public Dog(String name, int age, String color) {
        this.name = name;
        this.age = age;
        this.color = color;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", color='" + color + '\'' +
                '}';
    }
}
